package com.example.eventlistener.controller;

import com.example.eventlistener.bean.User;
import com.example.eventlistener.event.UserEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ActiveController {

    @Autowired
    private ApplicationEventPublisher publisher;

//    private ApplicationEventMulticaster multicaster;

    @PostMapping("/active")
    public User activeUser(@RequestParam String name, @RequestParam String email) {
        User user = new User();
        user.setName(name);
        user.setEmail(email);
        System.out.println("****: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName());
        UserEvent userEvent = new UserEvent(this, user);
        publisher.publishEvent(userEvent);
        return user;
    }
}
